export const check = (m, fields) => {
  if (m.combinator !== undefined) {
    if (m.children.length === 0) return true
    return m.children.some(el => check(el, fields))
  } else {
    if (m.field === undefined) return true
    const field = fields.find((f) => f.id === m.id)
    if (!field) return true
    switch (field['field_component']) {
      case 'input':
      case 'textarea':
        if (['one_of'].includes(m.operator)) {
          return m.operator === undefined || m.value.length === 0
        } else if (['empty', 'not_empty'].includes(m.operator)) {
          return m.operator === undefined
        } else {
          return m.operator === undefined || m.value === undefined
        }
      case 'number':
        if (['between', 'not_between'].includes(m.operator)) {
          return m.operator === undefined || m.value.some((v) => v === undefined)
        } else {
          return m.operator === undefined || m.value === undefined
        }
      case 'date':
      case 'datetime':
      case 'time':
        if (['between', 'not_between'].includes(m.operator)) {
          return m.operator === undefined || m.value.length === 0 || !m.value
        } else {
          return m.operator === undefined || m.value === undefined || !m.value
        }
      case 'select':
        if (['one_of'].includes(m.operator)) {
          return m.operator === undefined || m.value.length === 0 || !m.value
        } else {
          return m.operator === undefined || m.value === undefined || !m.value
        }
      default:
        return false
    }
  }
}